// 路由配置
import Layout from "@/pages/Layout";
import Login from "@/pages/Login";
// 配置路由实例
import { createBrowserRouter } from "react-router-dom";
import  AuthRoute  from "@/components/AuthRoute"
// import Home from "@/pages/Home";
// import Article from "@/pages/Article";
// import Publish from "@/pages/Publish";
import { lazy, Suspense } from "react";
// 1. lazy函数对组件进行导入
const Home = lazy(() => import('@/pages/Home'))
const Article = lazy(() => import('@/pages/Article'))
const Publish = lazy(() => import('@/pages/Publish'))

const router = createBrowserRouter([
    {
        path:"/",
        // 在此行代码中Layout作为参数传入给了AutoRoute并实行了一定的判断
        element:<AuthRoute><Layout/></AuthRoute>,
        children: [
            {
                path:'home',
                element:<Suspense fallback={"加载中"}><Home></Home></Suspense>
            },
            {
                path:'article',
                element:<Suspense fallback={"加载中"}><Article></Article></Suspense>
            },
            {
                path:'publish',
                element:<Suspense fallback={"加载中"}><Publish></Publish></Suspense>
            }
        ]
    },
    {
        path:"/login",
        element:<Login/>
    }
])
export default router